import { Terminal, ITerminalOptions } from "xterm";

export interface TerminalApi {
  clearLog: () => void;
  writeln: (text?: string) => void;
  write: (text?: string) => void;
  getCommand: () => string;
  resize: () => void;
}

export type XTerminal = Terminal & {
  _core: {
    buffer: {
      x: number;
    };
  };
};

export type Validator = (text: string) => boolean;

export type ColorRule = { pattern: RegExp; color: Color };

export interface XtermTerminalProps {
  width?: number;
  height?: number;
  style?: React.CSSProperties;
  onCommand?: (command?: string) => void;
  onClear?: () => void;
  onCopy?: (text: string) => Promise<void>;
  onPaste?: () => Promise<string>;
  disableStdin?: boolean;
  preLog?: string;
  command?: string;
  onLoad?: (term: XTerminal, api: TerminalApi) => void;
  className?: string;
  lineTitle?: string;
  colorRules?: ColorRule[]; // 更改一行的文本显示颜色
  options?: ITerminalOptions;
}

export type Color =
  | "BLACK"
  | "RED"
  | "GREEN"
  | "YELLOW"
  | "BLUE"
  | "MAGENTA"
  | "CYAN"
  | "WHITE"
  | "RESET";

export type TextConfig = {
  text: string;
  color: Color;
};
